<template>
  <view v-if="visible" class="update-banner" :class="{ 'show': isShow }">
    <view class="banner-content">
      <view class="banner-icon">🎉</view>
      <view class="banner-text">
        <text class="banner-title">发现新版本 v{{ updateInfo.remoteVersion || '1.0.0' }}</text>
        <text class="banner-desc">{{ updateInfo.message || '点击升级体验新功能' }}</text>
      </view>
      <view class="banner-actions">
        <button class="btn-later" @click="handleIgnore">稍后再说</button>
        <button class="btn-upgrade" @click="handleUpgrade">立即升级</button>
      </view>
      <view class="banner-close" @click="handleClose">×</view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'UpdateBanner',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    updateInfo: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      isShow: false
    }
  },
  watch: {
    visible(newVal) {
      if (newVal) {
        // 延迟显示，触发动画
        setTimeout(() => {
          this.isShow = true
        }, 100)
      } else {
        this.isShow = false
      }
    }
  },
  methods: {
    handleUpgrade() {
      console.log('[UpdateBanner] 用户点击立即升级')
      this.$emit('upgrade')
    },
    handleIgnore() {
      console.log('[UpdateBanner] 用户点击稍后再说')
      this.$emit('ignore')
      this.isShow = false
      setTimeout(() => {
        this.$emit('close')
      }, 300)
    },
    handleClose() {
      console.log('[UpdateBanner] 用户点击关闭')
      this.$emit('close')
      this.isShow = false
    }
  }
}
</script>

<style scoped>
.update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15);
  transform: translateY(-100%);
  transition: transform 0.3s ease-out;
}

.update-banner.show {
  transform: translateY(0);
}

.banner-content {
  display: flex;
  align-items: center;
  padding: 24rpx 32rpx;
  position: relative;
}

.banner-icon {
  font-size: 48rpx;
  margin-right: 24rpx;
  flex-shrink: 0;
}

.banner-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8rpx;
  min-width: 0;
}

.banner-title {
  font-size: 28rpx;
  font-weight: bold;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.banner-desc {
  font-size: 24rpx;
  color: rgba(255, 255, 255, 0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.banner-actions {
  display: flex;
  gap: 16rpx;
  margin-left: 24rpx;
  flex-shrink: 0;
}

.btn-later,
.btn-upgrade {
  padding: 16rpx 32rpx;
  border-radius: 8rpx;
  font-size: 24rpx;
  border: none;
  white-space: nowrap;
}

.btn-later {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.btn-upgrade {
  background: #ffffff;
  color: #667eea;
  font-weight: bold;
}

.banner-close {
  position: absolute;
  top: 16rpx;
  right: 16rpx;
  width: 48rpx;
  height: 48rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40rpx;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  flex-shrink: 0;
}

/* 响应式设计 - 小屏幕 */
@media screen and (max-width: 750rpx) {
  .banner-content {
    flex-wrap: wrap;
    padding: 20rpx 24rpx;
  }
  
  .banner-text {
    flex: 1 1 100%;
    margin-bottom: 16rpx;
  }
  
  .banner-actions {
    margin-left: 72rpx;
    flex: 1;
  }
  
  .btn-later,
  .btn-upgrade {
    flex: 1;
    padding: 12rpx 20rpx;
    font-size: 22rpx;
  }
}
</style>
